//双端队列deque
#include <iostream>
#include <deque>
using namespace std;

int main(int argc, char const *argv[])
{
    deque<int> q;

    q.push_back(1);
    q.push_back(2);
    
    q.push_front(0);

    for(auto i : q)
        cout << i << " ";
    cout << endl;

    cout << q.front() << endl;
    cout << q.back() << endl;

    cout << q[1] << endl;
    cout << q[8] << endl;   //越界，系统不会做出检查

    try
    {
        cout << q.at(1) << endl;
        cout << q.at(8) << endl;    //越界，系统会抛出异常
    }
    catch(const std::exception& e)
    {
        std::cerr << e.what() << '\n';
    }
    
    q.erase(q.begin());

    return 0;
}
